<template>
	<view class="content">
		<view class="title">
			<view>收入记录</view>
			<view>累计：￥{{money}}</view>
		</view>
		<view class="info" v-if="list.length>0">
			<view class="item" v-for="(item,i) in list">
				<image src="@/static/img/record_img.png" mode="widthFix"></image>
				<view class="type">
					<view>{{item.text}}</view>
					<view class="max_title">{{item.title||''}}</view>
					<view class="text">{{item.create_time}}</view>
				</view>
				<view class="money">￥{{item.money}}</view>
			</view>
		</view>
		<view class="default_btn btn" @click="open()">
			<uni-icons type="plus" size="24" color="white"></uni-icons>
			<text>添加</text>
		</view>
		<image v-if="list.length<1" class="none" src="@/static/img/img_none.png" mode="widthFix"></image>
		
		<uni-popup ref="popup" background-color="#fff" @change="change">
			<view class="box box2">
				<image src="@/static/img/diong3.png" mode="widthFix"></image>
				<view class="b_title">添加其他收入</view>
				<view class="text2">
					<image src="@/static/img/box_5.png" mode="widthFix"></image>
					标题
				</view>
				<input placeholder="请输入标题" type="text" v-model="title" />
				<view class="text2">
					<image src="@/static/img/box_1.png" mode="widthFix"></image>
					金额
				</view>
				<input type="number" placeholder="请输入金额" v-model="price" />
				<view class="btns">
					<view class="" @click="cancel()">取消</view>
					<view class="" @click="add()">确定</view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import {
		otherRevenue,addOtherRevenue
	} from '@/common/js/index.js'
	export default {
		data() {
			return {
				page: 1,
				list: '',
				money: '',
				isAll: false,
				title: '',
				price: '',
			}
		},
		onLoad() {
			this.record()
		},
		methods: {
			add() {
				this.cancel()
				addOtherRevenue({title:this.title,money:this.price}).then(res=>{
					if(res.code==200) {
						this.record()
						uni.showToast({
							title:'添加成功',
							icon:'none'
						})
					}else {
						uni.showToast({
							title:res.msg,
							icon:'none'
						})
					}
					this.title = ''
					this.price = ''
					console.log(res);
				})
			},
			tab(e) {
				this.tabIndex = e
				this.page = 1
				this.record()
			},
			open() {
				this.$refs.popup.open('center')
			},
			cancel() {
				this.$refs.popup.close()
			},
			record() {
				otherRevenue({
					page: this.page
				}).then(res => {
					console.log(res);
					this.money = res.data.total_money
					var info = this.list
					if (this.page == 1) {
						this.list = res.data.list
					} else {
						this.list = info.concat(res.data.list)
					}
					this.isAll = this.list.length < 10 ? false : true
				})
			}
		},
		onReachBottom() {
			console.log(this.isAll);
			if (this.isAll) {
				this.page++;
				this.record()
			}
		}
	}
</script>


<style scoped lang="scss">
	.content {
		position: relative;
		overflow: hidden;
	}
	.title {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin: 40rpx 30rpx 0;
	}

	.info {
		background-color: white;
		margin: 30rpx 30rpx;
		padding: 0 30rpx 50rpx;
		border-radius: 12rpx;

		.item {
			height: 150rpx;
			border-bottom: 2rpx solid #EEEEEE;
			display: flex;
			justify-content: space-between;
			align-items: center;

			image {
				width: 56rpx;
				margin-right: 20rpx;
			}
			
			.max_title {
				max-width: 360rpx;
				// background-color: #E99552;
				display: -webkit-box;
				  -webkit-box-orient: vertical;
				  overflow: hidden;
				  text-overflow: ellipsis;
				  -webkit-line-clamp: 2; /* 设置显示的行数为两行 */
				  /* 注意：在非微信小程序中需要同时设置以下两个属性 */
				  display: -webkit-box; /* 兼容性处理 */
				  -webkit-box-pack: start; /* 使文本从顶部开始显示 */
			}

			.type {
				flex: 1;
			}

			.text {
				font-size: 26rpx;
				color: #999999;
				margin-top: 12rpx;
			}

			.money {
				font-weight: 500;
				font-size: 32rpx;
				color: #E99552;
			}
		}
	}

	.none {
		width: 440rpx;
		display: block;
		margin: 240rpx auto 0;
	}
	
	.btn {
		display: flex;
		align-items: center;
		justify-content: center;
		position: fixed;
		bottom: 70rpx;
		left: 145rpx;
		text {
			margin-left: 12rpx;
		}
	}
	.box2 {
	
		width: 650rpx;
		// height: 896rpx;
		background-color: white;
		border-radius: 22rpx;
	
		image {
			width: 650rpx;
			display: block;
		}
	
		input {
			margin-bottom: 30rpx !important;
		}
	
		.btns {
	
			view {
				margin-top: 22rpx !important;
			}
		}
	}
	
	.box {
		overflow: hidden;
	
		.b_title {
			text-align: center;
			font-weight: 500;
			font-size: 36rpx;
			margin: 40rpx 0;
		}
	
		.text {
			margin: 0 40rpx 0;
			font-size: 25rpx;
			margin-top: 20rpx;
			color: red;
	
		}
	
		input {
			height: 68rpx;
			background: #FFFFFF;
			border-radius: 8rpx;
			margin: 0 40rpx 20rpx;
			padding: 0 16rpx;
			border: 2rpx solid #F69D5E;
			font-size: 26rpx;
		}
	
		.uni-input-placeholder {
			color: #999999;
		}

		.text2 {
			margin: 0 40rpx 20rpx;
			font-size: 28rpx;
			display: flex;
			align-items: center;
	
			image {
				width: 48rpx;
				margin-right: 16rpx;
			}
		}
		.btns {
			display: flex;
			justify-content: space-between;
	
			view {
				width: 220rpx;
				height: 80rpx;
				line-height: 80rpx;
				text-align: center;
				font-size: 32rpx;
				font-weight: 500;
				border-radius: 40rpx;
				margin: 52rpx 40rpx;
	
				&:nth-of-type(1) {
					border: 2rpx solid #FFA19E;
					color: #FF534E;
				}
	
				&:nth-of-type(2) {
					background: linear-gradient(to right, #F69F60 0%, #FF706D 100%);
					color: white;
				}
			}
		}
	}
	
	/deep/ .uni-popup__wrapper {
		background-color: rgba(0, 0, 0, 0) !important;
	}
</style>